package smedi.ismedi.web.bff.controller.report;


import brave.http.HttpServerResponse;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.smedi.ismedi.report.api.exception.SystemExcption;
import com.smedi.ismedi.report.api.feign.RemoteReportExportFeign;
import com.smedi.ismedi.report.api.feign.RemoteReportFillFeginApi;
import com.smedi.ismedi.report.api.model.vo.*;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RequestMapping(value = "/webbff/v1/fill")
@RestController
@Api(tags = {"填报表单"})
public class RemoteReportFillController {

    // test
  @Autowired

  private   RemoteReportFillFeginApi  remoteReportFillFeginApi;


  @ApiOperation("填报表单初始化")
  @GetMapping("/report/{taskId}/{model}")
  public ResponseData<OtherFillVO> getFillMsg(@ApiParam(value = "任务id",required = true) @PathVariable("taskId") Long taskId,@ApiParam(value = "model=1(仅查询当前任务id的表单数据),model=2(汇总子流程表单数据,不同表单后台汇总逻辑不一样)",required = true) @PathVariable("model") String model){

    return remoteReportFillFeginApi.getFillMsg(taskId,model);
  }

  @ApiOperation("填报表单数据汇总")
  @GetMapping("/report/collect/{taskId}")
  ResponseData<String>  collect(@PathVariable("taskId")Long taskId){

    return remoteReportFillFeginApi.collect(taskId);
  }

  @ApiOperation("填报子流程详情")
  @GetMapping("/from/{taskId}")
  ResponseData<ReportFromVO>  from(@PathVariable("taskId") Long taskId){
    return remoteReportFillFeginApi.from(taskId);
  }

    @ApiOperation("总院获取项目提交明细")
    @GetMapping("/projects/{taskId}")
    ResponseData<List<ProjectCommitInfoVo>> getProjectCommitInfos(@PathVariable("taskId") Long taskId){
        return remoteReportFillFeginApi.getProjectCommitInfos(taskId);
    }

  @Autowired
  RemoteReportExportFeign remoteReportExportFeign;




    @PostMapping({"/export/file"})
    @ApiOperation("填报导出表单")
   public void execl(@RequestBody  ReportExportVO reportExportVO,HttpServletResponse response){
        ResponseData<byte[]> test = remoteReportExportFeign.export( reportExportVO);
        try {
            response.getOutputStream().write(test.getData());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @ApiOperation("质量管理工作月度报告“质量交底”明细情况")
    @GetMapping("/quality/{taskId}/{qualityType}")
    public ResponseData<OtherFillQualityVO> getSubFillTypeMsg(@ApiParam(value = "任务id",required = true) @PathVariable("taskId") Long taskId,
                                                              @ApiParam(value = "zljd,zlgm,jypx,sygj,syhnt,syqtcl,sygnx,ysybys,ysgjgx,ysfxgc,ysfbgc,dwgc,zlts",required = true) @PathVariable("qualityType") String qualityType){
        return remoteReportFillFeginApi.getSubFillTypeMsg(taskId, qualityType);
    }

    @ApiOperation("上海表单初始化")
    @GetMapping("/from/shanghai/{taskId}")
    public ResponseData<Map<String,Integer>> getSubFillTypeMsg(@PathVariable("taskId") Long taskId){
        return remoteReportFillFeginApi.getShanghaiCount(taskId);
    }
}
